#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
void dh(int p[], int n);
int main()
{
	int n,i;
    int *p;
    while(~scanf("%d",&n))
	{
        p = (int *)calloc(n,sizeof(int));
            for ( i = 0; i < n; i++)
            scanf("%d", &p[i]);
            dh(p,n);
        free(p);
    }
	return 0;
}
void dh(int p[], int n)
{
    int i=0,star,end;//star为第一个0的位置，end为最后一个0的位置
    star = 0;
    end = 0;
    while (i<n)
    {
        if(p[i]==0)
        {
            star = i;
            end = i;
            break;
        }
        i++;
    }
    i++;
    while(i<n)
    {
        if(p[i]==0)
        end = i;
        else
        {
            p[star] = p[i];
            p[i] = 0;
            star++;
            end++;
        }
        i++;
    }
    for ( i = 0; i < n; i++)
    {
        printf("%d",p[i]);
        if(i<n-1)
        printf(" ");
    }
    printf("\n");
}
